//
//  KSTempSegVC.swift
//  ANOA
//
//  Created by 邱仙凯 on 2023/6/14.
//  Copyright © 2023 zwb. All rights reserved.
//

import UIKit

class KSTempSegVC: KSSegmenteController {
    
    var rootTemp = MainTempModel(JSON:["":""])!
    
    var currentIndex = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.title = rootTemp.menu_nm
        
        setupUI()
        
        configRightItem(ind: currentIndex)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func configRightItem(ind:Int) {
        let vc = self.children[ind]
        self.navigationItem.rightBarButtonItems = vc.navigationItem.rightBarButtonItems
    }
    
    // MARK: - Private Method
    func setupUI() {
        edgesForExtendedLayout = UIRectEdge()
        view.backgroundColor = Theme.BACKGROUND_COLOR
        
        let referTitles = rootTemp.referModels.compactMap{$0.menu_nm}
        
        var subViewControllers = [UIViewController]()
        
        for item in rootTemp.referModels {
            let vc = KSTempListVC()
            vc.configRightClo = {
                self.configRightItem(ind: self.currentIndex)
            }
            vc.rootTemp = item
            
            subViewControllers.append(vc)
        }
        
        config(titles: referTitles, vcs: subViewControllers)
    }
    
    override func ksSegmenteControllerMoveTo(index: Int) {
        super.ksSegmenteControllerMoveTo(index: index)
        
        self.currentIndex = index
        
        configRightItem(ind: index)
    }
}
